<?php
/**
 * @name SampleModel
 * @desc sample数据获取类, 可以访问数据库，文件，其它系统等
 * @author root
 */
class RobotsModel
{
    public function __construct()
    {
        $this->db = Yaf_Registry::get('db');
        $this->time = date("Y-m-d H:i:s",time());
    }

    public function selectRobots($start,$everyPage)
    {
        $sql = "select * from `collection_robot` limit {$start},{$everyPage}";
        return $this->db->query($sql);
    }

	public function selectRobotsName($website)
	{
       $sql="select * from `collection_robot` where website='{$website}' ";
	}

    public function getRobotsInfo()
    {
        $sql = "select * from `collection_robot` ";
        return $this->db->query($sql);
    }

    public function getAllCount()
    {
        $sql="select count(*) as `rows` from `collection_robot` ";
        return $this->db->query($sql);
    }

    public function del($id)
    {
        $sql = "delete from collection_robot where robot_id='{$id}' ";
        return $this->db->query($sql);
    }

    public function add($info)
    {           
        $sql="insert into collection_robot(`name`,`website_id`,`article_type_id`,`robot`,`chanel_website`,`status`,`remark`,`create_time`) values('{$info["fileName"]}','{$info["name"]}','{$info["type"]}','{$info["robot"]}','{$info["address"]}','{$info['status']}','{$info["remark"]}',UNIX_TIMESTAMP('{$this->time}'))";
        /*if(file_exists($_SERVER['DOCUMENT_ROOT'].'/caiji/'.$info["docu_file"])){
            $myfile = fopen($_SERVER['DOCUMENT_ROOT'].'/caiji/'.$info["docu_file"]."/".$info["fileName"].".js", "w");
        }
        else{
            exit;
        }*/
        return $this->db->query($sql);
    }

    public function edit($info, $id)
    {
        //$this->db->query("update collection_sites set web='{$info['name']}'  where website_id='{$info['website_id']}' ");
        $sql = "update `collection_robot` set `name`='{$info['file']}',`website_id`='{$info['name']}',`article_type_id`='{$info['article_type_id']}',`robot`='{$info['robot']}', `chanel_website`='{$info['address']}',`status`='{$info['status']}',`remark`='{$info['remark']}',`create_time`=UNIX_TIMESTAMP('{$this->time}') WHERE `robot_id`='{$id}'";
        return $this->db->query($sql);
    }
}

